﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using BSCMFF.Core.BusinessLayer;

namespace BSCMFF.Web.UserControls
{
    public partial class SelectEmployer : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //PopulateEmployees(null);
            }
        }

        private void PopulateEmployees(int? SBU_ID)
        {
            UserManager um = new UserManager();

            if (SBU_ID == null)
            {
                RadComboBoxEmployee.DataSource = um.GetAllUsers();
            }
            else
            {
                RadComboBoxEmployee.DataSource = um.GetAllUsersByDepartment((int)SBU_ID);
            }
            RadComboBoxEmployee.DataBind();
            //RadComboBoxEmployee.Enabled = true;
        }

        protected void RadComboBoxProduct_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
        {

            //string sqlSelectCommand = "SELECT [ProductID], [ProductName], [UnitPrice], [UnitsInStock] from [Products] WHERE [ProductName] LIKE @text + '%' ORDER BY [ProductName]";

            //SqlDataAdapter adapter = new SqlDataAdapter(sqlSelectCommand,
            //    ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString);
            //adapter.SelectCommand.Parameters.AddWithValue("@text", e.Text);
            //DataTable dataTable = new DataTable();
            //adapter.Fill(dataTable);



            //foreach (DataRow dataRow in dataTable.Rows)
            //{
            //    RadComboBoxItem item = new RadComboBoxItem();

            //    item.Text = (string)dataRow["ProductName"];
            //    item.Value = dataRow["ProductID"].ToString();

            //    decimal unitPrice = (decimal)dataRow["UnitPrice"];
            //    short unitsInStock = (short)dataRow["UnitsInStock"];

            //    item.Attributes.Add("UnitPrice", unitPrice.ToString());
            //    item.Attributes.Add("UnitsInStock", unitsInStock.ToString());

            //    item.Value += ":" + unitPrice;

            //    RadComboBoxProduct.Items.Add(item);

            //    item.DataBind();
            //}
        }

        protected void RadComboBoxDepartment_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            //RadComboBoxEmployee.Enabled = false;
            //PopulateEmployees(Int32.Parse(RadComboBoxDepartment.SelectedValue));
        }
    }
}